<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

include 'smarty/Smarty.class.php';
include 'app/includes/SmartLoader.php';

$album = "";
if(isset ($_GET['album'])) {
    $album = str_replace("." ,"" , $_GET['album']); // TODO: better security!
}

$admin = new Admin(Config::$admin_username, Config::$admin_password);
if(isset($_POST['username']) && isset($_POST['password'])) {
    $admin->login($_POST['username'], $_POST['password']);
}

$smarty = new Smarty();
$smarty->assign('show_login', (isset($_GET['show_login'])));
$smarty->assign('admin', $admin);
$smarty->assign('album_home_url', Config::$script_url);
$smarty->assign('album_title', Config::$album_title);
$smarty->assign('navigation', ServicesFactory::getImagesService()->getFoldersNavigation($album));
$smarty->assign('folders', ServicesFactory::getImagesService()->getFoldersTree($album , "", 1)->getChildren());
$images = ServicesFactory::getImagesService()->getImages($album);
$smarty->assign('images', $images);
$smarty->display('index.tpl');
?>